#include <iostream>
#include <map>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

void test(){
    map<int, string> number = {
        {1,"hello"},
        {2,"word"},
        {3,"wangdao"},
        {4,"加油"},
        pair<int, string>(5,"未来"),
        pair<int, string>(6,"光明"),
        make_pair(7,"shenzhen"),
        make_pair(9,"zhuanqian"),
        make_pair(8,"15000")
    };
    map<int, string>::iterator it = number.begin();
    while(it != number.end()){
        cout << (*it).first << it->second << endl;
        it++;
    }
}


// map的查找操作
void checkFind(map<int,string> & rhs, int key){
    auto it = rhs.find(key);
    if(it == rhs.end()){
        cout << "该元素不在map中！" << endl;
    }else{
        cout << "该元素在map中" << endl;
        cout << it->first << " " << it->second << endl;
    }
}
void test1(){
    map<int, string> number = {
        {1,"hello"},
        {2,"word"},
        {3,"wangdao"},
        {4,"加油"},
        pair<int, string>(5,"未来"),
        pair<int, string>(6,"光明"),
        make_pair(7,"shenzhen"),
        make_pair(9,"zhuanqian"),
        make_pair(8,"15000")
    };
    // 也是根据key值进行查找
    size_t cnt1 = number.count(10);
    size_t cnt2 = number.count(6);
    cout << "cnt1:" << cnt1 << endl;
    cout << "cnt2:" << cnt2 << endl;
    checkFind(number,6);
    cout << "##############" << endl;
    checkFind(number,10);
}

void test3(){
    map<int, string> number = {
        {1,"hello"},
        {2,"word"},
        {3,"wangdao"},
        {7,"加油"},
        pair<int, string>(6,"未来"),
        pair<int, string>(5,"光明"),
        make_pair(4,"15000")
    };
    number.insert(pair<int,string>(8,"shanghai"));
    for(auto & nu : number){
        cout << nu.first << nu.second << endl;
    }
    cout << endl;
    pair<map<int, string>::iterator,bool> ret =
    number.insert(pair<int, string>(30,"yesyesyes"));
    if(ret.second){
        cout << "该元素插入成功" << endl;
        cout << ret.first->first << " " << ret.first->second << endl;
    }else{
        cout << "该元素插入失败" << endl;
        cout << ret.first->first << " " << ret.first->second << endl;
    }

    number.insert({8,"nanjing"});
    number.insert(make_pair(10,"suzhou"));
    cout << "=====插入一组元素=====" << endl;
    map<int ,string> number2 = {{11,"zzzz"},{15,"sssss"}};
    number2.insert(number.begin(),number.end());
    for(auto & nu : number){
        cout << nu.first << " " << nu.second << endl;
    }

    number2.insert({{1,"begin"},{12,"end"}});;
    cout << endl;
    for(auto & nu : number2){
        cout << nu.first << " " << nu.second << endl;
    }
}

// 通过下标修改位置的值value
void test4(){
    map<int,string> number3 = {
        {1,"start"},
        {2,"se"},
        {3,"nihao"},
        {4,"naoer"}
    };
    for(auto & nu3 : number3){
        cout << nu3.first << " " << nu3.second << endl; 
    }
   cout << "通过下标来修改后的内容" << endl; 
    number3[1] = "hello";
    number3[2] = "word";
    for(auto & nu3 : number3){
        cout << nu3.first << " " << nu3.second << endl; 
    }

}
int main(int atgc, char * argv[])
{
    test4();
    return 0;
}

